using System.Linq;
using NUnit.Framework;
using WWB.DisqusSharp.Model.DisqusDTO;
using WWB.DisqusSharp.Model.DisqusService;
using WWB.DisqusSharp.Tests.TestUtility;

namespace WWB.DisqusSharp.Tests.ModelSerialization
{
    [TestFixture]
    [Category("Unit Tests")]
    public class ThreadCountPayloadTest
    {
        private IDisqusServiceResult<ForumPostCount> result;

        [TestFixtureSetUp] 
        public void ArrangeAndAct()
        {
            string json = "{\"message\": {\"thread1\": [5, 4], \"thread2\": [20, 15], \"thread3\":[2,0]}, \"code\": \"ok\", \"succeeded\": \"true\"}";
            result = new DisqusServiceResultWrapper<ForumPostCount>(json);
        }

        [Test]
        public void Result_should_be_successful_with_payload()
        {
            result.IsSuccessfulResult().WithPayload();
        }

        [Test]
        public void Should_have_three_items()
        {
            var fpc = result.WithPayload();
            Assert.That(fpc.PostCounts.Count(), Is.EqualTo(3));
        }

        [Test]
        public void Thread1_spot_check()
        {
            var pc = result.Payload.ForThread("thread1");
            Assert.That(pc, Is.Not.Null);
            Assert.That(pc.ThreadId, Is.EqualTo("thread1"));
            Assert.That(pc.VisiblePosts, Is.EqualTo(4));
            Assert.That(pc.AllPosts, Is.EqualTo(5));
        }

        [Test]
        public void Thread2_spot_check()
        {
            var pc = result.Payload.ForThread("thread2");
            Assert.That(pc, Is.Not.Null);
            Assert.That(pc.ThreadId, Is.EqualTo("thread2"));
            Assert.That(pc.VisiblePosts, Is.EqualTo(15));
            Assert.That(pc.AllPosts, Is.EqualTo(20));
        }

        [Test]
        public void Thread3_spot_check()
        {
            var pc = result.Payload.ForThread("thread3");
            Assert.That(pc, Is.Not.Null);
            Assert.That(pc.ThreadId, Is.EqualTo("thread3"));
            Assert.That(pc.VisiblePosts, Is.EqualTo(0));
            Assert.That(pc.AllPosts, Is.EqualTo(2));
        }

    }
}